package cn.laixueit.controller;

import cn.laixueit.pojo.Goods;
import cn.laixueit.pojo.GoodsDetail;
import cn.laixueit.result.Result;
import cn.laixueit.service.GoodsService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/goods")
public class GoodsController {

    @Autowired
    private GoodsService goodsService;

    @PostMapping("save")
    public Result save(@RequestBody Goods goods){
        goodsService.save(goods);
        return new Result();
    }

    @PostMapping("/listpage")
    public PageInfo<Goods> listPage(@RequestParam(defaultValue = "1") Integer startPage, @RequestParam(defaultValue = "10") Integer pageSize,String sortby, @RequestBody Goods goods){
        PageInfo<Goods> pageInfo = goodsService.listPage(startPage, pageSize,sortby, goods);
        return pageInfo;
    }

    @GetMapping("/findGoodsById/{id}")
    public Goods findGoodsById(@PathVariable("id")Long id){
        Goods goods = goodsService.findGoodsById(id);
        return goods;
    }

    @PostMapping("/update")
    public Result update(@RequestBody Goods goods){
        goodsService.update(goods);
        return new Result();
    }

    @GetMapping("/delById/{id}")
    public Result delById(@PathVariable("id")Long id){
        goodsService.delById(id);
        return new Result();
    }

}
